<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">

  <title>max</title>
  <link href="../cppreference.css" rel="stylesheet" type="text/css">
</head>

<body>
<table>
  <tr>
  <td>
  <div class="body-content">

  <div class="header-box">
    <a href="../index.html">cppreference.com</a> &gt; <a href=
    "index.html">C++ Algorithms</a> &gt; <a href="max.html">max</a>
  </div>

  <div class="name-format">
    max
  </div>

  <div class="syntax-name-format">
    Syntax:
  </div>
  <pre class="syntax-box">
  #include &lt;algorithm&gt;
  const <a href="../containers.html">TYPE</a>&amp; max( const <a href=
"../containers.html">TYPE</a>&amp; x, const <a href=
"../containers.html">TYPE</a>&amp; y );
  const <a href="../containers.html">TYPE</a>&amp; max( const <a href=
"../containers.html">TYPE</a>&amp; x, const <a href=
"../containers.html">TYPE</a>&amp; y, BinPred p );
</pre>

  <p>The max() function returns the greater of <em>x</em> and
  <em>y</em>.</p>

  <p>If the binary predicate <em>p</em> is given, then it will be used
  instead of the &lt; operator to compare the two elements.</p>

  <div class="related-examples-format">
    Example code:
  </div>

  <div class="related-examples">
    <p>For example, the following code snippet displays various uses of
    the max() function:</p>
    <pre class="example-code">
 cout &lt;&lt; &quot;Max of 1 and 9999 is &quot; &lt;&lt; max( 1, 9999) &lt;&lt; endl;
 cout &lt;&lt; &quot;Max of &#39;a&#39; and &#39;b&#39; is &quot; &lt;&lt; max( &#39;a&#39;, &#39;b&#39;) &lt;&lt; endl;
 cout &lt;&lt; &quot;Max of 3.14159 and 2.71828 is &quot; &lt;&lt; max( 3.14159, 2.71828) &lt;&lt; endl;                
</pre>

    <p>When run, this code displays:</p>
    <pre class="example-code">
 Max of 1 and 9999 is 9999
 Max of &#39;a&#39; and &#39;b&#39; is b
 Max of 3.14159 and 2.71828 is 3.14159          
</pre>
  </div>

  <div class="related-name-format">
    Related topics:
  </div>

  <div class="related-content">
    <a href="max_element.html">max_element</a><br>
    <a href="min.html">min</a><br>
    <a href="min_element.html">min_element</a>
  </div>
  </div>
  </td>
  


  </tr>
  </table>
</body></html>
